<?php

namespace App\Modules\Partner\Controllers;

use App\Lib\Facades\FLAuth;
use App\Lib\Utilities;
use App\Modules\Partner\Services\PartnerService;
use Flower\Core\Http\BaseController;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class PartnerController extends BaseController
{
    private $partnerService;

    public function __construct(PartnerService $partnerService)
    {
        $this->partnerService = $partnerService;
    }

    /*
     * 获取邀请新商家记录
     */
    public function getInviteStoreRecord(Request $request)
    {
        $list = $this->partnerService->getInviteStoreRecord($request->all());

        return $this->display($list,'查询成功');
    }

    /*
     * 获取提现记录
     */
    public function getWithdraw(Request $request)
    {
        $data_rule = [
            'scene' => '缺少场景值',
            'status' => '缺少状态值'
        ];

        Utilities::checkRequestDataKeyExist($request->all(),$data_rule);
        $user_id = FLAuth::id();
        $scene = $request->input('scene');
        $status = $request->input('status');
        $pageSize = $request->input('pageSize',10);

        $list = $this->partnerService->getWithdraw($user_id,$scene,$status,$pageSize);

        return $this->display($list,'查询成功');
    }

    /*
     * 申请提现
     */
    public function applyWithdraw(Request $request)
    {
        $this->partnerService->applyWithdraw($request->all());

        return $this->success('操作成功');
    }

    /*
     * 获取达标指数头部
     */
    public function getStandardIndexHeader(Request $request)
    {
        $user_id = FLAuth::id();
        $data = $this->partnerService->getStandardIndexHeader($user_id);

        return $this->display($data,'查询成功');
    }

    /*
     * 获取达标指数
     */
    public function getStandardIndex(Request $request)
    {
        $user_id = FLAuth::id();
        $data = $this->partnerService->getStandardIndex($user_id);

        return $this->display($data,'查询成功');
    }

    /*
     * 获取个人账单
     */

    public function getUserAccount()
    {
        $data = $this->partnerService->getUserAccount();

        return $this->display($data,'查询成功');
    }

    /**
     * 查询邀请码是否存在
     * @param Request $request
     * @return mixed
     * @throws \App\Exceptions\AllValidatorException
     */
    public function isExistInviteCode(Request $request)
    {
        $data_rule = [
            'invite_code' => '缺少邀请码'
        ];
        Utilities::checkRequestDataKeyExist($request->all(),$data_rule);
        $invite_code = $request->input('invite_code');
        $this->partnerService->isExistInviteCode($invite_code);
        return $this->success('查询成功');
    }


    /**
     * 邀请图
     * @param Request $request
     */
    public function inviteImg(Request $request)
    {

        $img = $this->partnerService->inviteImg();

        return $this->display($img);
    }

    /**
     * 获取分享可提现金额
     * @param Request $request
     */
    public function getShareWithdrawMoneyNow(Request $request)
    {

        $user_id = FLAuth::id();

        $data = $this->partnerService->getShareWithdrawMoneyNow($user_id);

        return $this->display($data,'查询成功');

    }
    /**
     * 获取分红可提现金额
     * @param Request $request
     */
    public function getBonusWithdrawMoneyNow(Request $request)
    {

        $user_id = FLAuth::id();

        $data = $this->partnerService->getBonusWithdrawMoneyNow($user_id);

        return $this->display($data,'查询成功');

    }
    /**
     * 获取总赚取金额
     * @param Request $request
     */
    public function getWithdrawMoneyAll(Request $request)
    {

        $user_id = FLAuth::id();

        $data = $this->partnerService->getWithdrawMoneyAll($user_id);

        return $this->display($data,'查询成功');

    }
}
